home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / Sound / SPlayer / Socks5 / src / lib / confutil.h < prev    next >
C/C++ Source or Header  |  1998-07-20  |  5KB  |  149 lines

  1. /* Copyright (c) 1995,1996,1997 NEC Corporation.  All rights reserved.       */
  2. /*                                                                           */
  3. /* The redistribution, use and modification in source or binary forms of     */
  4. /* this software is subject to the conditions set forth in the copyright     */
  5. /* document ("Copyright") included with this distribution.                   */
  6.  
  7. /*
  8.  * $Id: confutil.h,v 1.16.4.1 1998/07/19 22:33:22 wlu Exp $
  9.  */
  10.  
  11. #ifndef CONFUTIL_H
  12. #define CONFUTIL_H
  13.  
  14. #ifdef HAVE_SYS_SOCKIO_H
  15. #include <sys/sockio.h>
  16. #endif
  17.  
  18. #ifdef __alpha__                /* avoid some warnings                       */
  19. #ifdef HAVE_SYS_MBUF_H
  20. #include <sys/mbuf.h>
  21. #endif
  22.  
  23. #ifdef HAVE_NET_ROUTE_H
  24. #include <net/route.h>
  25. #endif
  26. #endif
  27.  
  28. #include <net/if.h>
  29. #define ifssi(x) ((ssi *)&(x.ifr_addr))
  30.  
  31. #define SKIPSPACE(x)     while(*(x) != '\n' &&  isspace((int)(*(x)))) (x)++
  32. #define SKIPNONSPACE(x)  while(*(x) != '\0' && !isspace((int)(*(x)))) (x)++
  33. #define SKIPNSPNCOMMA(x) while(*(x) != '\0' && !isspace((int)(*(x))) && *(x) != ',') (x)++
  34. #define SKIPNSPNCOLNCOM(x) while(*(x) != '\0' && !isspace((int)(*(x))) && *(x) != ',' && *(x) != ':') (x)++
  35.     
  36. #define S5_HOSTALIASES_NUM 16
  37. #define S5_HOSTIP_NUM       16
  38.  
  39. #define NET_STAT 0
  40. #define NET_ADDR 1
  41. #define NET_MASK 2
  42. #define NET_TYPE 3
  43.  
  44. #define IN_ADDR 0        /* is the type for address                    */
  45. #define IN_PORT 0        /* is the type d_port (is it a port range?)   */
  46. #define NAME    1        /* is the type for name                       */
  47.  
  48. /* a struct telling us how the address is stored...(for matching). It can be  */
  49. /* stred as an ip address and mask (type = IN_ADDR) or as a string/substring  */
  50. /* (type = NAME).                                                             */
  51. struct host {
  52.     char type;
  53.     char resolve;
  54.     struct in_addr ip;
  55.     struct in_addr mask;
  56.     char name[S5_HOSTNAME_SIZE];
  57.     int length;
  58.     char aliases[S5_HOSTALIASES_NUM][S5_HOSTNAME_SIZE];
  59.     int aliascnt;
  60.     struct in_addr back[S5_HOSTIP_NUM];
  61.     int ipcnt;
  62. };
  63.  
  64. /* a struct telling us how the service is stored...(for matching). It can be  */
  65. /* stred as an ip port range (type = IN_PORT) or as a string & fallback port  */
  66. /* (type = NAME).                                                             */
  67. struct port {
  68.     u_short lport;
  69.     u_short hport; 
  70. };
  71.  
  72. /* a structure contains the interface's IP address and mask                   */
  73. struct intaddr {
  74.     struct in_addr ip;
  75.     struct in_addr net;
  76. };
  77.  
  78. /* a structure contains interfaces' information                               */
  79. struct intfc {
  80.     char name[16];
  81.     int type;
  82.     int up;
  83.     int addrcnt;
  84.     struct intaddr *addrlist;
  85. };
  86.  
  87. /* macros for using struct port...they hide the union-ness of it all....      */
  88. #define checkport(x, y) (((x) >= (y).lport) && ((x) <= (y).hport))
  89.  
  90. /* macros for using struct intaddr...      */
  91. #define checkifc(x, y) (((x).net.s_addr != 0) && (((x).ip.s_addr & (x).net.s_addr) == ((y).s_addr & (x).net.s_addr)))
  92.  
  93. /* A generic structure for linked lists...Pretty straight forward...only thng */
  94. /* slightly unusual is the ptrmalloced field which tells us to free it or not */
  95. struct lls {
  96.   union data {
  97.     void *ptr;
  98.     int n;
  99.   } data;
  100.  
  101.   int ptrmalloced;
  102.   struct lls *next;
  103. };
  104.  
  105. typedef struct lls list;
  106.  
  107. #define dataptr data.ptr
  108. #define dataint data.n
  109.  
  110. struct confid { 
  111.     char *string, *abbrev;     /* the string/abbreviation for these lines   */
  112.     void (*handler)(void **, int, int, char *); /* the function for ""        */
  113.     void **array;         /* ptr to the array the data is stored in.   */
  114.     int *number;         /* ptr to the total number of things in ""   */
  115.     int *cnum;             /* ptr to the current index in array...      */
  116.     int size;             /* sizeof an array element (if owner)        */
  117. };
  118.  
  119. typedef struct confid confid;
  120.  
  121. /* Some convenient routines for linked list manipulation...                   */
  122. extern void lsDeleteLinkedList P((list **));
  123. extern int  lsLinkedListInsertUnaligned P((list **l, size_t s));
  124. extern int  lsLinkedListInsertAligned   P((list **l, size_t s));
  125.  
  126. extern int  lsGetHostAddress        P((char **, S5NetAddr *));
  127. extern int  lsGetHostPort           P((char **, S5NetAddr *));
  128. extern int  lsGetHostAddressAndPort P((char **, S5NetAddr *));
  129.  
  130. extern int  lsGetHostAndMask   P((char **, struct host *));
  131. extern int  lsGetPortOrService P((char **, struct port *));
  132. extern int  lsGetPermCommand   P((char **, list **));
  133. extern int  lsGetAuthMethods   P((char **, list **));
  134. extern int  lsGetPermUsers     P((char **, list **));
  135.  
  136. extern int  lsCheckHost  P((struct host *,  const S5NetAddr *, const char *));
  137. extern int  lsCheckPort  P((struct port *, const S5NetAddr *, const char *, char *));
  138. extern int  lsCheckByte  P((list *, u_char, const char *));
  139. extern int  lsCheckUser  P((list *, const char *));
  140.  
  141. extern void lsSetupIntfcs P((struct intfc **, int *));
  142. extern int  lsLookupIntfc P((S5IOHandle, int, struct ifreq *ifr));
  143.  
  144. extern void lsReadConfig P((const char *, struct confid *, int));
  145.  
  146. extern int lsLineNo;
  147.  
  148. #endif
  149.